﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.ParameterDecl"/>.
    /// </summary>
    public class ParameterDeclVM : VariableDeclVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(ParameterDecl),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new ParameterDeclVM((ParameterDecl)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.ParameterDecl"/>.
        /// </summary>
        public ParameterDeclVM(ParameterDecl parameterDecl, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(parameterDecl, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.ParameterDecl"/> model.
        /// </summary>
        public ParameterDecl ParameterDecl
        {
            get { return (ParameterDecl)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        /// <summary>
        /// Get the brush used to render the ParameterDecl.
        /// </summary>
        public virtual Brush RenderBrush()
        {
            // This can be overloaded with a KEYWORD_BRUSH for ValueParameterDecls and ArgListParameterDecls.
            return IDENTIFIER_BRUSH;
        }

        protected override void RenderStatement(CodeRenderer renderer, RenderFlags flags)
        {
            ParameterDecl parameterDecl = ParameterDecl;

            if (parameterDecl.Modifier != ParameterModifier.None)
            {
                renderer.RenderText(ParameterDecl.ParameterModifierToString(parameterDecl.Modifier), KEYWORD_BRUSH, this);
                renderer.RenderText(" ", PUNC_BRUSH, this);
            }
            RenderType(renderer, flags);

            renderer.RenderText(parameterDecl.Name, RenderBrush(), this);
        }

        #endregion
    }
}
